//
//  ViewController.m
//  弹幕
//
//  Created by tianlong on 2018/12/27.
//  Copyright © 2018年 tianlong. All rights reserved.
//

#import "ViewController.h"
#import "WXDanMu.h"
#import "WXDanMuHeader.h"
#import "Masonry.h"
#import "UIView+WXAutoLayout.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak,   nonatomic) UITableView *tableView;
@property (weak,   nonatomic) WXDanMu *danMu;
@property (strong, nonatomic) NSMutableArray *danMuArr;
@property (assign, nonatomic) int index;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.danMuArr = [NSMutableArray array];
    self.index = 0;
    
    //行高固定
    WXDanMu *danm = [[WXDanMu alloc] initWithDanMuDirection:DanMuDirectionVertical];
    danm.backgroundColor = [UIColor redColor];
    [self.view addSubview:danm];
    self.danMu = danm;
    
    CGFloat viewH = [self.danMu getViewHWithVisibleRows:10];
    [self.danMu mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(64);
        make.left.right.offset(0);
        make.height.offset(viewH);
    }];
}

- (IBAction)insertDanMu:(id)sender {
    WXDanMuMessage *msg  = [[WXDanMuMessage alloc] init];
    int a = arc4random_uniform(1000);
    if (a%2==0) {
        msg.content = [NSString stringWithFormat:@"阿里波波同学点了%d个赞!!",a];
    }
    
    else if (a%3==0){
        msg.content = [NSString stringWithFormat:@"无忌同学点了%d个赞!!",a];
        msg.isMyTeam = YES;
    }
    
    else if (a%5==0){
        msg.content = [NSString stringWithFormat:@"阿里科协马克西莫维奇彼什科夫同学点了%d个赞!!",a];
    }
    [self.danMu insertDanMuMessage:msg];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 20;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@""];
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 40;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
